package com.ruoyi.project.module.movicetype.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.module.movicetype.domain.Movicetype;
import com.ruoyi.project.module.movicetype.service.IMovicetypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 电影类型 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-13
 */
@Controller
@RequestMapping("/module/movicetype")
public class MovicetypeController extends BaseController
{
    private String prefix = "module/movicetype";
	
	@Autowired
	private IMovicetypeService movicetypeService;
	
	@RequiresPermissions("module:movicetype:view")
	@GetMapping()
	public String movicetype()
	{
	    return prefix + "/movicetype";
	}
	
	/**
	 * 查询电影类型列表
	 */
	@RequiresPermissions("module:movicetype:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Movicetype movicetype)
	{
		startPage();
        List<Movicetype> list = movicetypeService.selectMovicetypeList(movicetype);
		return getDataTable(list);
	}
	@Log(title = "用户管理", businessType = BusinessType.EXPORT)
	@RequiresPermissions("module:movicetype:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(Movicetype movicetype) throws Exception
	{

		try{

			List<Movicetype> list = movicetypeService.selectMovicetypeList(movicetype);
			ExcelUtil<Movicetype> util = new ExcelUtil<Movicetype>(Movicetype.class);
			return util.exportExcel(list, "Movicetype");

		}catch(Exception e){

			return error("到处exprot失败");
		}

	}
	/**
	 * 新增电影类型
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存电影类型
	 */
	@RequiresPermissions("module:movicetype:add")
	@Log(title = "电影类型", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Movicetype movicetype)
	{		
		return toAjax(movicetypeService.insertMovicetype(movicetype));
	}

	/**
	 * 修改电影类型
	 */
	@GetMapping("/edit/{typeid}")
	public String edit(@PathVariable("typeid") Integer typeid, ModelMap mmap)
	{
		Movicetype movicetype = movicetypeService.selectMovicetypeById(typeid);
		mmap.put("movicetype", movicetype);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存电影类型
	 */
	@RequiresPermissions("module:movicetype:edit")
	@Log(title = "电影类型", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Movicetype movicetype)
	{		
		return toAjax(movicetypeService.updateMovicetype(movicetype));
	}
	
	/**
	 * 删除电影类型
	 */
	@RequiresPermissions("module:movicetype:remove")
	@Log(title = "电影类型", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(movicetypeService.deleteMovicetypeByIds(ids));
	}


}
